package nl.mkmedia.tuio.behaviours {
	import flash.geom.Matrix;
	import flash.geom.Point;
	import flash.display.DisplayObject;
	import nl.mkmedia.tuio.TUIOPoint;

	/**
	 * @author Mingoes Kukupessy (mingoes at gmail dot com)
	 */
	public class BRotate {
		
		public static function callback(points:Array, displayObject:DisplayObject):void
		{
			if(points.length == 2) { 
				//trace(getAngle(points[0], points[1]));
				//if(points[0].oldX == 0 || points[0].oldY == 0 || points[1].oldX == 0 || points[1].oldY == 0) return;
				displayObject.rotation += getAngle(points[1], points[0]);
				displayObject.rotation += getAngle(points[0], points[1]);
				//displayObject.rotation += getAngle(points[0], points[1])*(Math.PI/180);
				trace(getAngle(points[1], points[0]));
			}
		}
		
		public static function getAngle(rotationPoint:TUIOPoint, rotatedPoint:TUIOPoint):Number
		{
			var d1:Number = Point.distance(rotatedPoint, new Point(rotatedPoint.oldX, rotatedPoint.oldY));
			var d2:Number = Point.distance(rotationPoint, rotatedPoint);
			return Math.acos(d1 / d2) * (180 / Math.PI);
		}
		
		public function rotate(rotationPoint:TUIOPoint, angle:Number):void
		{
			
		}
	}
}
